# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=innoextract

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.4
pkgrel=1
pkgdesc="A tool to extract installers created by Inno Setup (mingw-w64)."
arch=('any')
url="http://constexpr.org/innoextract/"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" 
      "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-boost"
    "${MINGW_PACKAGE_PREFIX}-xz"
    "${MINGW_PACKAGE_PREFIX}-zlib"
    "${MINGW_PACKAGE_PREFIX}-bzip2"
    "${MINGW_PACKAGE_PREFIX}-libiconv")
options=('staticlibs' '!strip')
source=("http://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz"
    fix-typo-in-comment.patch
    fix-crash-on-startup.patch
    dont-set-background.patch
    fix-flickering-progress-bar.patch
    fix-restoring-original-console-color.patch
    fix-an-infinite-loop-with-truncated-LZMA-streams.patch)
sha1sums=('3fd3ac98c802c72a1f4ae5f6e6a5dca35747ff98'
          '554408d4be410563828d2599db698f0f76cef51e'
          'd35974339a83db0cd04c343d865075d99fc426ba'
          'abebb02453cd1d60afee5f4fb19ad0dc53d09125'
          '43454e4e6ef70cd635135e38ead7e596308986c0'
          '665c7cbb712d88e0d6506b3de157d7fbf819c239'
          '69798ae9a93e0f944201889b6b7000130a7af4d4')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/fix-typo-in-comment.patch
  patch -p1 -i ${srcdir}/fix-crash-on-startup.patch
  patch -p1 -i ${srcdir}/dont-set-background.patch
  patch -p1 -i ${srcdir}/fix-flickering-progress-bar.patch
  patch -p1 -i ${srcdir}/fix-restoring-original-console-color.patch
  patch -p1 -i ${srcdir}/fix-an-infinite-loop-with-truncated-LZMA-streams.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  cd "${srcdir}/${_realname}-${pkgver}"
  
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCMAKE_BUILD_TYPE=Release \
    -DUSE_STATIC_LIBS=OFF
  make
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}" 
  make install

  install -Dm644 README.md \
    "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
  install -Dm644 CHANGELOG \
    "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/CHANGELOG"
  install -Dm644 LICENSE \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
